/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.test.mock;

import lombok.Data;
import org.jrose.api.annotation.persistence.Column;
import org.jrose.api.annotation.persistence.CreateTimestamp;
import org.jrose.api.annotation.persistence.MongoEntity;
import org.jrose.api.annotation.persistence.PrimaryKey;
import org.jrose.api.annotation.persistence.Revision;
import org.jrose.api.annotation.persistence.Table;
import org.jrose.api.annotation.persistence.UpdateTimestamp;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.Date;

@Data
@Table("MOCK_BOOK")
@Document(collection = "MOCK_BOOK")
@MongoEntity(database = "mock", readPreference = MongoEntity.ReadPreference.PRIMARY)
// database 'mock' will be automatically decorated to 'test'
public class MockBook implements Serializable {
    private static final long serialVersionUID = -7037219094059493543L;

    @Id
    @PrimaryKey(index = 1, autoInc = true) private Long id;
    @PrimaryKey(index = 2, name = "SERIAL") private String serialNo;
    @CreateTimestamp(name = "CREATETIME") private Long createTime;
    @UpdateTimestamp(name = "UPDATETIME") private Date updateTime;
    @Revision private Integer revision;
    @Indexed
    @Column(notNull = true) private String name;
    @Column(defaultValue = @Column.DefaultValue("")) private String press;
    @Column(defaultValue = @Column.DefaultValue("true")) private Boolean active;
    @Column(defaultValue = @Column.DefaultValue("0")) private Integer level;
    @Column private Double price;
    @Column(defaultValue = @Column.DefaultValue("ONLINE")) private BookStatus status;

    public MockBook() {
    }

    public MockBook(String name) {
        this.name = name;
    }

    public static enum BookStatus {
        ONLINE, OFFLINE
    }
}
